const API_BASE = 'https://your-domain.com/api'

const request = (url, method, data) => {
    return new Promise((resolve, reject) => {
        wx.request({
            url: API_BASE + url,
            method: method,
            data: data,
            header: {
                'Content-Type': 'application/json',
                'Authorization': wx.getStorageSync('token')
            },
            success(res) {
                if (res.statusCode === 200) {
                    resolve(res.data)
                } else {
                    reject(res.data)
                }
            },
            fail(err) {
                reject(err)
            }
        })
    })
}

export default {
    // 首页API
    getMasters(location, page = 1, pageSize = 10) {
        return request('/home/getMasterData', 'GET', { location, page, pageSize })
    },
    getRecycleStations(location, page = 1, pageSize = 10) {
        return request('/home/getRecycleData', 'GET', { location, page, pageSize })
    },
    getNotices() {
        return request('/home/getNoticeData', 'GET')
    },

    // 价格API
    getPrices(categoryId) {
        return request('/price/getPriceList', 'GET', { categoryId })
    },
    getPriceNotices() {
        return request('/price/getPriceNoticeData', 'GET')
    },

    // 订单API
    getCategories() {
        return request('/order/getCategoryList', 'GET')
    },
    getTimeSlots(date) {
        return request('/order/getOrderTimeList', 'GET', { date })
    },
    submitOrder(data) {
        return request('/order/submitOrder', 'POST', data)
    },

    // 用户API
    getUserInfo() {
        return request('/user/getUserInfo', 'GET')
    },
    getOrders(status, page = 1, pageSize = 10) {
        return request('/user/getOrderList', 'GET', { status, page, pageSize })
    },
    getOrderDetail(orderId) {
        return request('/user/getOrderDetail', 'GET', { orderId })
    },

    // 认证API
    login(code) {
        return request('/auth/login', 'POST', { code })
    },
    refreshToken() {
        return request('/auth/refreshToken', 'POST')
    }
}